home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / emula / arosdv19.lha / AROS / dos / flush.c < prev    next >
C/C++ Source or Header  |  1996-10-24  |  2KB  |  100 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: flush.c,v 1.4 1996/10/24 15:50:29 aros Exp $
  4.     $Log: flush.c,v $
  5.     Revision 1.4  1996/10/24 15:50:29  aros
  6.     Use the official AROS macros over the __AROS versions.
  7.  
  8.     Revision 1.3  1996/08/13 13:52:46  digulla
  9.     Replaced <dos/dosextens.h> by "dos_intern.h" or added "dos_intern.h"
  10.     Replaced AROS_LA by AROS_LHA
  11.  
  12.     Revision 1.2  1996/08/01 17:40:51  digulla
  13.     Added standard header for all files
  14.  
  15.     Desc:
  16.     Lang: english
  17. */
  18. #include <dos/dosextens.h>
  19. #include <clib/dos_protos.h>
  20.  
  21. /*****************************************************************************
  22.  
  23.     NAME */
  24.     #include <clib/dos_protos.h>
  25.  
  26.     AROS_LH1(LONG, Flush,
  27.  
  28. /*  SYNOPSIS */
  29.     AROS_LHA(BPTR, file, D1),
  30.  
  31. /*  LOCATION */
  32.     struct DosLibrary *, DOSBase, 60, Dos)
  33.  
  34. /*  FUNCTION
  35.     Flushes any pending writes on the file. If the file was used
  36.     for input and there is still some data to read it tries to
  37.     seek back to the expected position.
  38.  
  39.     INPUTS
  40.     file - filehandle
  41.  
  42.     RESULT
  43.     !=0 on success, 0 on error. IoErr() gives additional information
  44.     in that case.
  45.  
  46.     NOTES
  47.  
  48.     EXAMPLE
  49.  
  50.     BUGS
  51.  
  52.     SEE ALSO
  53.  
  54.     INTERNALS
  55.  
  56.     HISTORY
  57.     29-10-95    digulla automatically created from
  58.                 dos_lib.fd and clib/dos_protos.h
  59.  
  60. *****************************************************************************/
  61. {
  62.     AROS_LIBFUNC_INIT
  63.     AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
  64.  
  65.     /* Get pointer to filehandle */
  66.     struct FileHandle *fh=(struct FileHandle *)BADDR(file);
  67.     long success=1;
  68.  
  69.     /* If the file is in write mode... */
  70.     if(fh->fh_Flags&FHF_WRITE)
  71.     {
  72.     UBYTE *pos;
  73.     /* Unset write flag */
  74.     fh->fh_Flags&=~FHF_WRITE;
  75.  
  76.     /* Write the data. (In many pieces if the first one isn't enough). */
  77.     pos=fh->fh_Buf;
  78.         while(pos!=fh->fh_Pos)
  79.         {
  80.             LONG size;
  81.         size=Write(file,pos,fh->fh_Pos-pos);
  82.  
  83.         /* An error happened? No success. */
  84.         if(size<0)
  85.         {
  86.             success=0;
  87.         break;
  88.         }
  89.         pos+=size;
  90.     }
  91.     }else if(fh->fh_Pos<fh->fh_End)
  92.         /* Read mode. Try to seek back to the current position. */
  93.         if(Seek(file,fh->fh_Pos-fh->fh_End,OFFSET_CURRENT)<0)
  94.             success=0;
  95.     /* Reinit the buffer and return. */
  96.     fh->fh_Pos=fh->fh_End=fh->fh_Buf;
  97.     return success;
  98.     AROS_LIBFUNC_EXIT
  99. } /* Flush */
  100.